export default class Food{
    constructor(map){
        this.map=map

        //自己创建一个食物
        this.food = document.createElement('div')
        this.food.className = 'food'

        //插入地图
        this.map.appendChild(this.food);

        //准备两个变量记录坐标
        this.x=0
        this.y=0
        this.newFood()

    }
    newFood(){

        // 1-1 计算横向 纵向 能放下多少食物
        const xNum = this.map.clientWidth / 20
        const yNum = this.map.clientHeight / 20

        //1-2 随机出现
        const x =Math.floor(Math.random()*xNum)
        const y =Math.floor(Math.random()*yNum)

        //1-3 *20
        this.x=x*20
        this.y=y*20

        //1-4 给this.ele 赋值
        this.food.style.left = this.x +'px'
        this.food.style.top = this.y +'px'
    }

}